import {HTTP} from '../util/http-p'

class KeywordModel extends HTTP{
    key = 'q';
    maxLength = 10;
    getHistory() {
        const words = wx.getStorageSync(this.key)
        if (!words) {
            return []
        }
        return words
    }
    getHot() {
        return this.request({
            url:'book/hot_keyword'
        })
    }
    addToHistory(keywords) {
        const words = this.getHistory()
        const has = words.includes(keywords)
        if (!has) {
            if (words.length >= this.maxLength) {
                words.pop()
            }
            words.unshift(keywords)
            wx.setStorageSync(this.key, words);
        }
    }
}
export {KeywordModel}